﻿Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.IO

Namespace DotNetNuke.Modules.ActiveForums.Controls
    <ToolboxData("<{0}:ForumLoader runat=server></{0}:ForumLoader>")> _
    Public Class ForumLoader
        Inherits ForumBase
        Private fi As Forum
        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                If ForumId > 0 And ForumModuleId = -1 Then
                    Dim fc As New ForumController
                    fi = fc.Forums_Get(ForumId, UserId, True, True)
                    ForumModuleId = fi.ModuleId
                End If
                If ForumModuleId > 0 Then
                    'Dim mc As New DotNetNuke.Entities.Modules.ModuleController
                    'Dim arrMods As ArrayList = mc.GetModule(ForumModuleId)
                    'Dim modInfo As DotNetNuke.Entities.Modules.ModuleInfo = Nothing
                    'For Each mi As DotNetNuke.Entities.Modules.ModuleInfo In arrMods
                    '    If mi.ModuleID = ForumModuleId Then
                    '        modInfo = mi
                    '        Exit For
                    '    End If
                    'Next
                    Dim modInfo As New DotNetNuke.Entities.Modules.ModuleInfo
                    modInfo.TabID = TabId
                    modInfo.ModuleID = ForumModuleId
                    modInfo.PortalID = PortalId
                    modInfo.DesktopModule.Permissions = Me.ModuleConfiguration.DesktopModule.Permissions

                    'Dim mi As DotNetNuke.Entities.Modules.ModuleInfo = mc.GetModule(ForumModuleId, ForumTabId)
                    Dim objModule As ForumBase = CType(LoadControl("~/desktopmodules/ActiveForums/classic.ascx"), ForumBase)
                    If Not objModule Is Nothing Then
                        objModule.ModuleConfiguration = modInfo
                        objModule.ID = Path.GetFileNameWithoutExtension("~/desktopmodules/ActiveForums/classic.ascx")
                        objModule.ForumModuleId = ForumModuleId 'CType(Settings("AFForumModuleID"), Integer)
                        objModule.ForumInfo = fi
                        objModule.ForumId = ForumId
                        objModule.ForumGroupId = ForumGroupId
                        objModule.DefaultForumViewTemplateId = DefaultForumViewTemplateId
                        objModule.DefaultTopicsViewTemplateId = DefaultTopicsViewTemplateId
                        objModule.DefaultTopicViewTemplateId = DefaultTopicViewTemplateId
                        objModule.TemplatePath = TemplatePath
                        objModule.UseTemplatePath = UseTemplatePath
                        objModule.ParentForumId = ParentForumId
                        objModule.ForumIds = ForumIds
                        objModule.InheritModuleCSS = InheritModuleCSS
                        'objModule.LoadGroupForumID = CType(Settings("AFForumGroupID"), Integer)
                        objModule.DefaultView = DefaultView 'CType(Settings("AFViewType"), String)
                        Me.Controls.Add(objModule)
                    End If
                Else
                    Dim lblMessage As New Label
                    lblMessage.Text = "Please access the Module Settings page to configure this module."
                    lblMessage.CssClass = "NormalRed"
                    Me.Controls.Add(lblMessage)
                End If
            Catch exc As Exception
                DotNetNuke.Services.Exceptions.ProcessModuleLoadException(Me, exc)
            End Try
        End Sub
    End Class
End Namespace
